1. Technical Field
The present invention relates in general to a system and method for optimized specular highlight generation. More particularly, the present invention relates to a system and method for generating a specular highlight intensity value using a single microprocessor instruction command.
2. Description of the Related Art
Specular highlights are used in 3D graphics to simulate the reflection of a light source on a surface. In typical real time 3D graphics software such as a video game, several estimation algorithms are used to simulate these highlights in a high-speed manner, without using more calculation intensive operations, such as ray tracing. To produce these specular highlights, the rate at which the highlight fades from its lightest color in the center to the darkest outer portion is calculated by the formula:Intensity=exp2(k*log 2(Cos(θ))
Where k is a property of the surface (a higher number corresponding to a smoother surface) and theta is an angle between a ray that connects the surface with a viewing position, and a ray that represents the reflection off the surface from a light source, sometimes referred to as a “viewing angle.”
This intensity value is typically calculated with several microprocessor instructions, which are a base 2 logarithm instruction, a multiply-add instruction, and a power of 2 exponentiation instruction. These three instructions are typically executed in a vector floating point pipeline, which has some common components to facilitate log, power, multiply and add instructions.
A challenge found with existing art is that, when each instruction executes, a significant portion of the floating-point pipeline is unused for each instruction. The base 2 logarithm instruction completes its result calculation very quickly, in time to pass through a leading zero anticipator and adder without any changes. The multiply-add instruction only adds zero during an intensity value calculation, thereby making the add step unneeded. The power of two instruction performs a fraction calculation near the end of the pipeline since it needs an integer and fraction portion from an aligner. Therefore, the time that is normally spent performing a multiply in other instructions is wasted with the power of two instruction.
Another challenge found with existing art is register dependency. Using a series of instructions, the result of the log instruction must be present before the multiply instruction starts, and the result of the multiply instruction must be present before the power of two instruction starts. Therefore, the instructions must be executed in order and their target registers cannot be overwritten between instructions. In some architectures, “new” instructions may stall until a result with a dependency is completed. This may have a significant impact on performance.
What is needed, therefore, is a system and method for calculating specular highlights in a more efficient and effective manner than what exists in the prior art.